package com.event;

import com.mysqld.Mysqld;
import com.window.Register;

import javax.swing.*;
import java.awt.event.*;

public class AccountEvent implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        jbutton();
    }

    void jbutton() {
        //判断所有空格不能为空
        char[] str = Register.passwordtext.getPassword();//获取密码
        char[] str1 = Register.okpasswordtext.getPassword();
        String password = new String(str);
        String okpassword = new String(str1);

        if (Register.nametext.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "姓名不能为空", "信息注册", JOptionPane.WARNING_MESSAGE);
        } else if (Register.accounttext.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "账号不能为空!", "注册信息", JOptionPane.WARNING_MESSAGE);
        } else if (password.equals("")) {
            JOptionPane.showMessageDialog(null, "密码不能为空!", "注册信息", JOptionPane.WARNING_MESSAGE);
        } else if (okpassword.equals("")) {
            JOptionPane.showMessageDialog(null, "确认密码不能为空!", "注册信息", JOptionPane.WARNING_MESSAGE);
        }
        //判断密码与确认密码相同
        else if (password.equals(okpassword) == false) {
            JOptionPane.showMessageDialog(null, "密码与确认密码要相同!", "注册信息", JOptionPane.WARNING_MESSAGE);
        } else {
            try {
                Mysqld.writeRegister();
                JOptionPane.showMessageDialog(null, "注册成功!", "注册信息", JOptionPane.WARNING_MESSAGE);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "当前账号已经存在!", "注册信息", JOptionPane.WARNING_MESSAGE);
            }


        }
    }
}

